﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using DataModels.Models;
using System.Linq;
using DataModels.Common;
using DataModels.Enumerations;
using GenericTools.OptionBPlus;
using DataModels.Models.Context;
using DHISInteroperability.Authentication;

namespace GenericTools.Tests.OptionBPlus
{
    /// <summary>
    ///This is a test class for ANCFormValidatorTest and is intended
    ///to contain all ANCFormValidatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FormValidatorTest
    {
        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            AppConfiguration.AccessMethod = DataModels.Enumerations.DataAccessMethod.DIRECT_ACCESS;
            AppConfiguration.DBConnectionString = @"Data Source=(local)\SQLEXPRESS;Initial Catalog=IQSMS_TestDB.Development;Integrated Security=True";          
            //AppConfiguration.DBConnectionString = Properties
        }
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        #region Public Interface/Interaction
        /// <summary>
        ///A test for ANCFormValidator Constructor
        ///</summary>
        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void _ANCFormValidatorConstructorTest()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            Assert.AreEqual(phoneNumber, target.PhoneNumber);
            Assert.AreEqual(message, target.Message);
        }

        /// <summary>
        ///A test for Dispose
        ///</summary>
        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void _DisposeTest()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            target.Dispose();
            Assert.IsNull(target.DbContext);
        }

        /// <summary>
        ///A test for Save
        ///</summary>
        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void _ANC_Form_SaveTest()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, "04010100");

            //string message = string.Format("ANC.{0},12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2", facilityCode);
            string message = string.Format("ANC.{0},12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2", facilityCode); 
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            //string phoneNumberOrUsername = "mkehengu";
            //string password = DataTransformation.Encrypt("changed");
            //DataInputingMethod inputMethod = DataInputingMethod.DESKTOP_DATA_CAPTURE;
            //var target = new ANCFormValidator(message, phoneNumberOrUsername, format, mode, inputMethod,
            //        password, true);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        /// <summary>
        ///A test for Save
        ///</summary>
        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void _MAT_Form_SaveTest()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, "04010100");

            string message = string.Format("MAT.{0},12,2013,C20,K8,65,5,0,3,7,1,0,1,6,6,0,0,0,1", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        /// <summary>
        ///A test for Validate
        ///</summary>
        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void _ValidateTest()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool expected = true;
            bool actual;
            actual = target.Validate();
            Assert.AreEqual(expected, actual, target.ReportingError.ErrorText);
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void Once_Created_The_Object_Is_Not_Checked_For_Errors()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            Assert.IsFalse(target.ValidatedForErrors, "When was the validation performed?");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Report_Keyword_Is_Valid()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.KeywordValid;
            Assert.AreEqual(bExpected, bExpected);

            ReportProcessingError rExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError rActual = target.ReportingError.Type;
            Assert.AreEqual(rExpected, rActual, target.ReportingError.ErrorText);

            Assert.AreEqual(target.Keyword, target.Keyword, true);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Report_Keyword_Is_Invalid_Restrictive_Mode()
        {
            string message = "Another Keyword.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.KeywordValid;
            Assert.AreEqual(bExpected, bExpected);

            ReportProcessingError rExpected = ReportProcessingError.REPORT_DOES_NOT_EXIST;
            ReportProcessingError rActual = target.ReportingError.Type;
            Assert.AreEqual(rExpected, rActual, target.ReportingError.ErrorText);

            Assert.IsNull(target.Keyword, target.Keyword);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Report_Keyword_Is_Invalid_In_Flexible_Mode()
        {
            string message = "Another Keyword.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.KeywordValid;
            Assert.AreEqual(bExpected, bExpected);

            ReportProcessingError rExpected = ReportProcessingError.REPORT_DOES_NOT_EXIST;
            ReportProcessingError rActual = target.ReportingError.Type;
            Assert.AreEqual(rExpected, rActual, target.ReportingError.ErrorText);

            Assert.IsNull(target.Keyword, target.Keyword);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Facility_Code_Is_Valid()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.FacilityCodeValid;
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            string sExpected = "04010100";
            string sActual = target.FacilityCode;
            Assert.AreEqual(sExpected, sActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Keyword_Is_Followed_By_Comma_In_Flexible_Mode()
        {
            string message = "ANC,04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.FacilityCodeValid;
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            string sExpected = "04010100";
            string sActual = target.FacilityCode;
            Assert.AreEqual(sExpected, sActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Facility_Code_Is_Invalid()
        {
            string phoneNumber = "+255763986451";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.qwertyu,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.FacilityCodeValid;
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            ReportProcessingError rExpected = ReportProcessingError.INVALID_FACILITY;
            ReportProcessingError rActual = target.ReportingError.Type;
            Assert.AreEqual(rExpected, rActual, target.ReportingError.ErrorText);
        }

        /// <summary>
        ///A test for HasError
        ///</summary>
        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void _HasErrorTest()
        {
            string phoneNumber = "+255713";
            string facilityCode = "04010100";
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            string message = "ANC.04010100,Janua,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            Assert.IsFalse(target.HasError, target.ReportingError.ErrorText);
        }
        #endregion

        #region Class Features
        [TestMethod]
        public void Report_Month_Is_Valid()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            int iExpected = 1;
            int iActual = target.ReportMonth;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Month_Text_Is_Valid()
        {
            string message = "ANC.04010100,Janua,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            int iExpected = 1;
            int iActual = target.ReportMonth;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Year_Is_Valid()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            int iExpected = 2014;
            int iActual = target.ReportYear;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }        

        [TestMethod()]
        public void Single_Report_Is_Saved()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var savedForms = target.SavedForms;
            int iExpected = 1;
            int iActual = savedForms.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
            
            ANCForm savedForm = savedForms[0];
            bExpected = true;
            bActual = savedForm.LessThan20;
            Assert.AreEqual(bExpected, bActual, "Age Category do not match with reporting text");

            ANCForm_PMTCT pmtct = savedForm.ANCForm_PMTCT;
            Assert.IsNotNull(pmtct, "Extended report section with data was saved or atleast linked to main form");
        }

        [TestMethod()]
        public void Single_Report_Data_Indicators_Are_Saved()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            ANCForm savedForm = savedForms[0];
            ANCForm_PMTCT pmtct = savedForm.ANCForm_PMTCT;

            Assert.IsTrue(pmtct.LessThan20, "Report age category was not save correctly");
            Assert.AreEqual(1, pmtct.C_5a, "Indicator 5a is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5b, "Indicator 5b is not saved correctly");
            Assert.AreEqual(7, pmtct.C_5c, "Indicator 5c is not saved correctly");
            Assert.AreEqual(2, pmtct.C_5d, "Indicator 5d is not saved correctly");
            Assert.AreEqual(5, pmtct.C_5e, "Indicator 5e is not saved correctly");
            Assert.AreEqual(1, pmtct.C_5f, "Indicator 5f is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5g, "Indicator 5g is not saved correctly");
            Assert.AreEqual(7, pmtct.C_5h, "Indicator 5h is not saved correctly");
            Assert.AreEqual(3, pmtct.C_5i, "Indicator 5i is not saved correctly");
            Assert.AreEqual(0, pmtct.C_5j, "Indicator 5j is not saved correctly");
            Assert.AreEqual(7, pmtct.C_5k, "Indicator 5k is not saved correctly");
            Assert.AreEqual(1, pmtct.C_5l, "Indicator 5l is not saved correctly");
            Assert.AreEqual(1, pmtct.C_5m, "Indicator 5m is not saved correctly");
            Assert.AreEqual(1, pmtct.C_5n, "Indicator 5n is not saved correctly");
            Assert.AreEqual(1, pmtct.C_5o, "Indicator 5o is not saved correctly");
            Assert.AreEqual(1, pmtct.C_5p, "Indicator 5p is not saved correctly");
            Assert.AreEqual(2, pmtct.C_5q, "Indicator 5q is not saved correctly");
        }

        [TestMethod]
        public void Multiple_Report_Data_Indicators_Are_Saved()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,1,2014,C20,K1,10,J20,K1,20";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            Assert.AreEqual(2, savedForms.Count, "Not all two reports were saved");

            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsTrue(firstSavedForm.LessThan20, "Report 1: Report age category was not saved correctly");
            Assert.IsFalse(secondSavedForm.LessThan20, "Report 2: Report age category was not saved correctly");

            Assert.AreEqual(10, firstSavedForm.C_1, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(20, secondSavedForm.C_1, "Report 2: Indicator 1 is not saved correctly");
        }

        [TestMethod]
        public void All_Inline_Report_Data_Indicators_Are_Saved()
        {
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, "04010100");

            string message = string.Format("ANC.{0},1,2014,C20,K1,1,c20,k3,2,c20,k7,3,c20,k8,4,c20,k9,5,c20,k10,6,j20,k1,7,j20,k3,8,j20,k7,9,j20,k8,10,j20,k9,11,J20,K10,12", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            Assert.AreEqual(2, savedForms.Count, "Not all two reports were saved - " + target.ReportingError.ErrorText);

            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsTrue(firstSavedForm.LessThan20, "Report 1: Report age category was not saved correctly");
            Assert.IsFalse(secondSavedForm.LessThan20, "Report 2: Report age category was not saved correctly");

            Assert.AreEqual(1, firstSavedForm.C_1, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(2, firstSavedForm.C_3, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(3, firstSavedForm.C_7, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(4, firstSavedForm.C_8, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(5, firstSavedForm.C_9, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(6, firstSavedForm.C_10, "Report 1: Indicator 6 is not saved correctly");

            Assert.AreEqual(7, secondSavedForm.C_1, "Report 2: Indicator 7 is not saved correctly");
            Assert.AreEqual(8, secondSavedForm.C_3, "Report 2: Indicator 8 is not saved correctly");
            Assert.AreEqual(9, secondSavedForm.C_7, "Report 2: Indicator 9 is not saved correctly");
            Assert.AreEqual(10, secondSavedForm.C_8, "Report 2: Indicator 10 is not saved correctly");
            Assert.AreEqual(11, secondSavedForm.C_9, "Report 2: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, secondSavedForm.C_10, "Report 2: Indicator 12 is not saved correctly");
        }

        [TestMethod]
        public void All_Inline_Report_Data_Indicators_Are_Saved_And_Updated()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,1,2014,C20,K1,1,c20,k3,2,c20,k7,3,c20,k8,4,c20,k9,5,c20,k10,6,j20,k1,7,j20,k3,8,j20,k7,9,j20,k8,10,j20,k9,11,J20,K10,12";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            Assert.AreEqual(2, savedForms.Count, "Not all two reports were saved");

            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsTrue(firstSavedForm.LessThan20, "Report 1: Report age category was not saved correctly");
            Assert.IsFalse(secondSavedForm.LessThan20, "Report 2: Report age category was not saved correctly");

            Assert.AreEqual(1, firstSavedForm.C_1, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(2, firstSavedForm.C_3, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(3, firstSavedForm.C_7, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(4, firstSavedForm.C_8, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(5, firstSavedForm.C_9, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(6, firstSavedForm.C_10, "Report 1: Indicator 6 is not saved correctly");

            Assert.AreEqual(7, secondSavedForm.C_1, "Report 2: Indicator 7 is not saved correctly");
            Assert.AreEqual(8, secondSavedForm.C_3, "Report 2: Indicator 8 is not saved correctly");
            Assert.AreEqual(9, secondSavedForm.C_7, "Report 2: Indicator 9 is not saved correctly");
            Assert.AreEqual(10, secondSavedForm.C_8, "Report 2: Indicator 10 is not saved correctly");
            Assert.AreEqual(11, secondSavedForm.C_9, "Report 2: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, secondSavedForm.C_10, "Report 2: Indicator 12 is not saved correctly");

            message = "ANC.04010100,1,2014,C20,K1,11,c20,k3,22,c20,k7,33,c20,k8,44,c20,k9,55,c20,k10,66,j20,k1,77,j20,k3,88,j20,k7,99,j20,k8,110,j20,k9,211,J20,K10,312,badili";
            target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();
            savedForms = target.SavedForms;
            firstSavedForm = savedForms[0];
            secondSavedForm = savedForms[1];

            Assert.AreEqual(11, firstSavedForm.C_1, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(22, firstSavedForm.C_3, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(33, firstSavedForm.C_7, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(44, firstSavedForm.C_8, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(55, firstSavedForm.C_9, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(66, firstSavedForm.C_10, "Report 1: Indicator 6 is not saved correctly");

            Assert.AreEqual(77, secondSavedForm.C_1, "Report 2: Indicator 7 is not saved correctly");
            Assert.AreEqual(88, secondSavedForm.C_3, "Report 2: Indicator 8 is not saved correctly");
            Assert.AreEqual(99, secondSavedForm.C_7, "Report 2: Indicator 9 is not saved correctly");
            Assert.AreEqual(110, secondSavedForm.C_8, "Report 2: Indicator 10 is not saved correctly");
            Assert.AreEqual(211, secondSavedForm.C_9, "Report 2: Indicator 11 is not saved correctly");
            Assert.AreEqual(312, secondSavedForm.C_10, "Report 2: Indicator 12 is not saved correctly");
        }

        [TestMethod]
        public void Updating_Existing_Report()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            // Inserting a report into the database.
            string message = "ANC.04010100,12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();
            target.Dispose();

            // Now we are updating the report.
            message = "ANC.04010100,12,2013,C20,K5,10,100,70,20,50,10,100,70,30,00,70,10,10,10,10,10,20";
            target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var savedForms = target.SavedForms;
            int iExpected = 1;
            int iActual = savedForms.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            ANCForm firstSavedForm = savedForms[0];
            bExpected = true;
            bActual = firstSavedForm.LessThan20;
            Assert.AreEqual(bExpected, bActual, "Age Category do not match with reporting text");

            ANCForm_PMTCT pmtct = firstSavedForm.ANCForm_PMTCT;
            Assert.IsNotNull(pmtct, "Extended report section with data was saved or atleast linked to main form");

            Assert.IsTrue(pmtct.LessThan20, "Report age category was not save correctly");
            Assert.AreEqual(10, pmtct.C_5a, "Indicator 5a is not saved correctly");
            Assert.AreEqual(100, pmtct.C_5b, "Indicator 5b is not saved correctly");
            Assert.AreEqual(70, pmtct.C_5c, "Indicator 5c is not saved correctly");
            Assert.AreEqual(20, pmtct.C_5d, "Indicator 5d is not saved correctly");
            Assert.AreEqual(50, pmtct.C_5e, "Indicator 5e is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5f, "Indicator 5f is not saved correctly");
            Assert.AreEqual(100, pmtct.C_5g, "Indicator 5g is not saved correctly");
            Assert.AreEqual(70, pmtct.C_5h, "Indicator 5h is not saved correctly");
            Assert.AreEqual(30, pmtct.C_5i, "Indicator 5i is not saved correctly");
            Assert.AreEqual(0, pmtct.C_5j, "Indicator 5j is not saved correctly");
            Assert.AreEqual(70, pmtct.C_5k, "Indicator 5k is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5l, "Indicator 5l is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5m, "Indicator 5m is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5n, "Indicator 5n is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5o, "Indicator 5o is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5p, "Indicator 5p is not saved correctly");
            Assert.AreEqual(20, pmtct.C_5q, "Indicator 5q is not saved correctly");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Updating_Existing_Multiple_Reports_In_Flexible_Mode()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            // Inserting a report into the database.
            string message = "ANC.04010100,12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2.C20,K1,10,J20,K1,20";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();
            target.Dispose();

            // Now we are updating the report.
            message = "ANC.04010100,12,2013,C20,K5,10,100,70,20,50,10,100,70,30,00,70,10,10,10,10,10,20.C20,K1,107,J20,K1,208";
            target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var savedForms = target.SavedForms;
            int iExpected = 2;
            int iActual = savedForms.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];
            bExpected = true;
            bActual = firstSavedForm.LessThan20;
            Assert.AreEqual(bExpected, bActual, "Age Category do not match with reporting text");

            ANCForm_PMTCT pmtct = firstSavedForm.ANCForm_PMTCT;
            Assert.IsNotNull(pmtct, "Extended report section with data was saved or atleast linked to main form");

            Assert.IsTrue(pmtct.LessThan20, "Report age category was not save correctly");
            Assert.AreEqual(10, pmtct.C_5a, "Indicator 5a is not saved correctly");
            Assert.AreEqual(100, pmtct.C_5b, "Indicator 5b is not saved correctly");
            Assert.AreEqual(70, pmtct.C_5c, "Indicator 5c is not saved correctly");
            Assert.AreEqual(20, pmtct.C_5d, "Indicator 5d is not saved correctly");
            Assert.AreEqual(50, pmtct.C_5e, "Indicator 5e is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5f, "Indicator 5f is not saved correctly");
            Assert.AreEqual(100, pmtct.C_5g, "Indicator 5g is not saved correctly");
            Assert.AreEqual(70, pmtct.C_5h, "Indicator 5h is not saved correctly");
            Assert.AreEqual(30, pmtct.C_5i, "Indicator 5i is not saved correctly");
            Assert.AreEqual(0, pmtct.C_5j, "Indicator 5j is not saved correctly");
            Assert.AreEqual(70, pmtct.C_5k, "Indicator 5k is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5l, "Indicator 5l is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5m, "Indicator 5m is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5n, "Indicator 5n is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5o, "Indicator 5o is not saved correctly");
            Assert.AreEqual(10, pmtct.C_5p, "Indicator 5p is not saved correctly");
            Assert.AreEqual(20, pmtct.C_5q, "Indicator 5q is not saved correctly");

            Assert.IsTrue(firstSavedForm.LessThan20, "Report 1: Report age category was not saved correctly");
            Assert.IsFalse(secondSavedForm.LessThan20, "Report 2: Report age category was not saved correctly");

            Assert.AreEqual(107, firstSavedForm.C_1, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(208, secondSavedForm.C_1, "Report 2: Indicator 1 is not saved correctly");
        }
        
        [TestMethod]
        public void IsUserRegisteredTest()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            //bool expected = true;
            bool actual = target.IsUserRegistered();
            Assert.IsTrue(actual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void User_Is_Not_Registered_In_IQSMS()
        {
            string message = "ANC.04010100,1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string phoneNumber = "+255713000000";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            //bool expected = true;
            bool actual = target.IsUserRegistered();
            Assert.IsFalse(actual);

            ReportProcessingError eExpected = ReportProcessingError.SENDER_NUMBER_IS_NOT_REGISTERED;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual);
        }

        [TestMethod]
        [Owner("Upendo Msanjila")]
        public void User_Is_Registered_But_Not_Reporting_Facility()
        {
            string phoneNumber = "+255713";
            string facilityCode = "04010100";
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            string reportingFacilityCode = "04010200";
            string message = string.Format("ANC.{0},1,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13", reportingFacilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            //bool expected = true;
            bool actual = target.IsUserRegistered();
            Assert.IsTrue(actual, target.ReportingError.ErrorText);

            string sExpected = reportingFacilityCode;
            string sActual = target.FacilityCode;
            Assert.AreEqual(sExpected, sActual, target.ReportingError.ErrorText);

            ReportProcessingError eExpected = ReportProcessingError.SENDER_NUMBER_IS_NOT_REGISTERED_FOR_SELECTED_FACILITY;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Number_Of_Resolved_Reports_Included()
        {
            string message = "ANC.04010100,Janua,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            // Testing number of reports resoleved
            int iExpected = 1;
            int iActual = target.ResolvedReports.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Age_Category_In_Single_Report()
        {
            string message = "ANC.04010100,Janua,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            ReportDataSegment reportDataSegment = target.ResolvedReports[0];
            
            // Testing report age category
            MTUHAAgeCategory aExpected = MTUHAAgeCategory.UNDER_20_YEARS;
            MTUHAAgeCategory aActual = reportDataSegment.AgeCategory;
            Assert.AreEqual(aExpected, aActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("George Binde")]
        public void Report_Segment_In_Single_Report()
        {
            string message = "ANC.04010100,Janua,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            ReportDataSegment reportDataSegment = target.ResolvedReports[0];
            
            // Testing report segment number
            int iExpected = 5;
            int iActual = reportDataSegment.SectionNumber;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Indicators_In_Single_Report()
        {
            string message = "ANC.04010100,Janua,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            ReportDataSegment reportDataSegment = target.ResolvedReports[0];

            // Testing number of indicators
            //int iExpected = 17; // Old version
            int iExpected = 19; // This is standard with ANCFormValidator
            int iActual = reportDataSegment.Indicators.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Number_Of_Two_Resolved_Reports_Included()
        {
            string message = "ANC.04010100,1,2014,C20,K1,10,J20,K1,20";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            // Testing number of reports resolved
            int iExpected = 2;
            int iActual = target.ResolvedReports.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Age_Category_In_Two_Reports()
        {
            string message = "ANC.04010100,1,2014,C20,K1,10,J20,K1,20";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            ReportDataSegment firstReportDataSegment = target.ResolvedReports[0];
            ReportDataSegment secondReportDataSegment = target.ResolvedReports[1];

            // Testing first report age category
            MTUHAAgeCategory aExpected = MTUHAAgeCategory.UNDER_20_YEARS;
            MTUHAAgeCategory aActual = firstReportDataSegment.AgeCategory;
            Assert.AreEqual(aExpected, aActual, target.ReportingError.ErrorText);

            // Testing second report age category
            aExpected = MTUHAAgeCategory.ABOVE_20_YEARS;
            aActual = secondReportDataSegment.AgeCategory;
            Assert.AreEqual(aExpected, aActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Segment_In_Two_Reports()
        {
            string message = "ANC.04010100,12,2014,C20,K1,10,J20,K1,20";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            ReportDataSegment firstReportDataSegment = target.ResolvedReports[0];
            ReportDataSegment secondReportDataSegment = target.ResolvedReports[1];

            // Testing first report segment number
            int iExpected = 1;
            int iActual = firstReportDataSegment.SectionNumber;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            // Testing second report segment number
            iExpected = 1;
            iActual = secondReportDataSegment.SectionNumber;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Report_Indicators_In_Two_Reports()
        {
            string message = "ANC.04010100,1,2014,C20,K1,10,J20,K1,20";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            ReportDataSegment firstReportDataSegment = target.ResolvedReports[0];
            ReportDataSegment secondReportDataSegment = target.ResolvedReports[1];

            // Testing first number of indicators
            int iExpected = 1;
            int iActual = firstReportDataSegment.Indicators.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            // Testing second number of indicators
            iExpected = 1;
            iActual = secondReportDataSegment.Indicators.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Business Rules")]
        public void Few_Report_Indicators()
        {
            //string message = "ANC.04010100,3,2013,C20,K6,1,2,3,4,5,J20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string message = "ANC.04010100,3,2013,C20,K6,1,2,3,4";  // Valid indicator count is 5
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            ReportProcessingError eExpected = ReportProcessingError.FEW_REPORT_PARAMETERS;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Business Rules")]
        public void Same_Month_Reporting_Is_Not_Allowed()
        {
            var now = DateTime.Now;
            //string message = "ANC.04010100,3,2013,C20,K6,1,2,3,4,5,J20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string message = string.Format("ANC.04010100,{0},{1},C20,K6,1,2,3,4", now.Month, now.Year);  // Valid indicator count is 5
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            ReportProcessingError eExpected = ReportProcessingError.CURRENT_MONTH_REPORTING_NOT_ALLOWED;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Business Rules")]
        public void Many_Report_Indicators()
        {
            //string message = "ANC.04010100,3,2013,C20,K6,1,2,3,4,5,J20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string message = "ANC.04010100,3,2013,C20,K6,1,2,3,4,5,6";  // Valid indicator count is 5
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            ReportProcessingError eExpected = ReportProcessingError.MANY_REPORT_PARAMETERS;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Abubakari Madhehebi")]
        public void Allow_Valid_To_End_With_Comma()
        {
            string message = "ANC.04010100,Jan,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2,";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            // Check the validity
            bool bExpected = true;
            bool bActual = target.Validate();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Dont_Allow_Valid_To_End_With_Period_In_Restrictive_Mode()
        {
            string message = "ANC.04010100,Jan,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NON_INTEGER_VALUE;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Abubakari Madhehebi")]
        public void Allow_Valid_To_End_With_Period_In_Flexible_Mode()
        {
            string message = "ANC.04010100,Jan,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Dont_Allow_FacilityCode_Adjustment_In_Restrictive_Mode()
        {
            string message = "ANC.04O1O100,Jan,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.INVALID_FACILITY;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Allow_FacilityCode_Adjustment_In_Flexible_Mode()
        {
            string message = "ANC.04O1O100,Jan,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            string sExpected = "04010100";
            string sActual = target.FacilityCode;
            Assert.AreEqual(sExpected, sActual, target.ReportingError.ErrorText);

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Treat_O_In_Month_As_Zero_In_Flexible_Mode()
        {
            string message = "ANC.o4o1o1OO,1o,2013,C20,K1,3,J20,K1,40.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            int iExpected = 10;
            int iActual = target.ReportMonth;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Treat_O_In_Year_As_Zero_In_Flexible_Mode()
        {
            string message = "ANC.o4o1o1OO,1o,2o13,C20,K1,3,J20,K1,40.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            int iExpected = 2013;
            int iActual = target.ReportYear;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Treat_O_In_Age_Category_As_Zero_In_Flexible_Mode()
        {
            string message = "ANC.o4o1o1OO,1o,2o13,C2o,K1,3,J20,K1,40.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            int iExpected = 2;
            int iActual = target.ResolvedReports.Count;
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Treat_O_In_Indicator_As_Zero_In_Flexible_Mode()
        {
            string message = "ANC.o4o1o1OO,1o,2o13,C2o,K1,3,J20,K1,4o.";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.FLEXIBLE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Validate();

            //ReportDataSegment firstReportDataSegment = target.ResolvedReports[0];
            ReportDataSegment secondReportDataSegment = target.ResolvedReports[1];

            int iExpected = 40;
            int iActual = secondReportDataSegment.Indicators[0];
            Assert.AreEqual(iExpected, iActual, target.ReportingError.ErrorText);

            // Check the validity
            ReportProcessingError eExpected = ReportProcessingError.NO_ERROR;
            ReportProcessingError eActual = target.ReportingError.Type;
            Assert.AreEqual(eExpected, eActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Saving_Hudhurio_La_Kwanza_Report_Segment()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,Janua,2014,J20,K2,1,2,3,4,5,7,7,C20,K2,8,9,17,11,12,28,14";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            bool bActual = target.Save();

            Assert.IsTrue(bActual, target.ReportingError.ErrorText);            
            var savedForms = target.SavedForms;
            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            var hudhurio1 = firstSavedForm.ANCForm_HudhurioLaKwanza;
            var hudhurio2 = secondSavedForm.ANCForm_HudhurioLaKwanza;

            Assert.AreEqual(1, hudhurio1.C_2a, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(2, hudhurio1.C_2b, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(3, hudhurio1.C_2c, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(4, hudhurio1.C_2d, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(5, hudhurio1.C_2e, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(7, hudhurio1.C_2f, "Report 1: Indicator 6 is not saved correctly");
            Assert.AreEqual(7, hudhurio1.C_2g, "Report 1: Indicator 7 is not saved correctly");

            Assert.AreEqual(8, hudhurio2.C_2a, "Report 2: Indicator 1 is not saved correctly");
            Assert.AreEqual(9, hudhurio2.C_2b, "Report 2: Indicator 2 is not saved correctly");
            Assert.AreEqual(17, hudhurio2.C_2c, "Report 2: Indicator 3 is not saved correctly");
            Assert.AreEqual(11, hudhurio2.C_2d, "Report 2: Indicator 4 is not saved correctly");
            Assert.AreEqual(12, hudhurio2.C_2e, "Report 2: Indicator 5 is not saved correctly");
            Assert.AreEqual(28, hudhurio2.C_2f, "Report 2: Indicator 6 is not saved correctly");
            Assert.AreEqual(14, hudhurio2.C_2g, "Report 2: Indicator 7 is not saved correctly");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Saving_And_Updating_Hudhurio_La_Kwanza_Report_Segment()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,Janua,2014,J20,K2,1,2,3,4,5,7,7,C20,K2,8,9,17,11,12,28,14";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();           

            message = "ANC.04010100,Janua,2014,J20,K2,10,21,31,43,54,74,76,C20,K2,87,98,185,110,121,295,143";
            target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            var hudhurio1 = firstSavedForm.ANCForm_HudhurioLaKwanza;
            var hudhurio2 = secondSavedForm.ANCForm_HudhurioLaKwanza;

            Assert.AreEqual(10, hudhurio1.C_2a, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(21, hudhurio1.C_2b, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(31, hudhurio1.C_2c, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(43, hudhurio1.C_2d, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(54, hudhurio1.C_2e, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(74, hudhurio1.C_2f, "Report 1: Indicator 6 is not saved correctly");
            Assert.AreEqual(76, hudhurio1.C_2g, "Report 1: Indicator 7 is not saved correctly");

            Assert.AreEqual(87, hudhurio2.C_2a, "Report 2: Indicator 1 is not saved correctly");
            Assert.AreEqual(98, hudhurio2.C_2b, "Report 2: Indicator 2 is not saved correctly");
            Assert.AreEqual(185, hudhurio2.C_2c, "Report 2: Indicator 3 is not saved correctly");
            Assert.AreEqual(110, hudhurio2.C_2d, "Report 2: Indicator 4 is not saved correctly");
            Assert.AreEqual(121, hudhurio2.C_2e, "Report 2: Indicator 5 is not saved correctly");
            Assert.AreEqual(295, hudhurio2.C_2f, "Report 2: Indicator 6 is not saved correctly");
            Assert.AreEqual(143, hudhurio2.C_2g, "Report 2: Indicator 7 is not saved correctly");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Saving_Vidokezo_Vya_Hatari_Report_Segment()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,Jan,2014,J20,K4,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,C20,K4,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            bool bActual = target.Save();

            Assert.IsTrue(bActual, target.ReportingError.ErrorText);
            var savedForms = target.SavedForms;
            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsNotNull(firstSavedForm.VidokezoVyaHatari_4id, "Report 1: Data Link was not established");
            Assert.AreEqual(firstSavedForm.VidokezoVyaHatari_4id, firstSavedForm.ANCForm_VidokezoVyaHatari.Id, 
                "Report 1: Established link does not match with report details");
            
            Assert.IsNotNull(secondSavedForm.VidokezoVyaHatari_4id, "Report 2: Data Link was not established");
            Assert.AreEqual(secondSavedForm.VidokezoVyaHatari_4id, secondSavedForm.ANCForm_VidokezoVyaHatari.Id,
                "Report 2: Established link does not match with report details");

            var vidokezo1 = firstSavedForm.ANCForm_VidokezoVyaHatari;
            var vidokezo2 = secondSavedForm.ANCForm_VidokezoVyaHatari;

            Assert.AreEqual(1, vidokezo1.C_4a, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(2, vidokezo1.C_4b, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(3, vidokezo1.C_4c, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(4, vidokezo1.C_4d, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(5, vidokezo1.C_4e, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(6, vidokezo1.C_4f, "Report 1: Indicator 6 is not saved correctly");
            Assert.AreEqual(7, vidokezo1.C_4g, "Report 1: Indicator 7 is not saved correctly");
            Assert.AreEqual(8, vidokezo1.C_4h, "Report 1: Indicator 8 is not saved correctly");
            Assert.AreEqual(9, vidokezo1.C_4i, "Report 1: Indicator 9 is not saved correctly");
            Assert.AreEqual(10, vidokezo1.C_4j, "Report 1: Indicator 10 is not saved correctly");
            Assert.AreEqual(11, vidokezo1.C_4k, "Report 1: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, vidokezo1.C_4l, "Report 1: Indicator 12 is not saved correctly");
            Assert.AreEqual(13, vidokezo1.C_4m, "Report 1: Indicator 13 is not saved correctly");
            Assert.AreEqual(14, vidokezo1.C_4n, "Report 1: Indicator 14 is not saved correctly");
            Assert.AreEqual(15, vidokezo1.C_4o, "Report 1: Indicator 15 is not saved correctly");
            Assert.AreEqual(16, vidokezo1.C_4p, "Report 1: Indicator 16 is not saved correctly");
            Assert.AreEqual(17, vidokezo1.C_4q, "Report 1: Indicator 17 is not saved correctly");
            Assert.AreEqual(18, vidokezo1.C_4r, "Report 1: Indicator 18 is not saved correctly");

            Assert.AreEqual(12, vidokezo2.C_4a, "Report 2: Indicator 1 is not saved correctly");
            Assert.AreEqual(13, vidokezo2.C_4b, "Report 2: Indicator 2 is not saved correctly");
            Assert.AreEqual(14, vidokezo2.C_4c, "Report 2: Indicator 3 is not saved correctly");
            Assert.AreEqual(15, vidokezo2.C_4d, "Report 2: Indicator 4 is not saved correctly");
            Assert.AreEqual(16, vidokezo2.C_4e, "Report 2: Indicator 5 is not saved correctly");
            Assert.AreEqual(17, vidokezo2.C_4f, "Report 2: Indicator 6 is not saved correctly");
            Assert.AreEqual(18, vidokezo2.C_4g, "Report 2: Indicator 7 is not saved correctly");
            Assert.AreEqual(19, vidokezo2.C_4h, "Report 2: Indicator 8 is not saved correctly");
            Assert.AreEqual(20, vidokezo2.C_4i, "Report 2: Indicator 9 is not saved correctly");
            Assert.AreEqual(21, vidokezo2.C_4j, "Report 2: Indicator 10 is not saved correctly");
            Assert.AreEqual(22, vidokezo2.C_4k, "Report 2: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, vidokezo1.C_4l, "Report 1: Indicator 12 is not saved correctly");
            Assert.AreEqual(13, vidokezo1.C_4m, "Report 1: Indicator 13 is not saved correctly");
            Assert.AreEqual(14, vidokezo1.C_4n, "Report 1: Indicator 14 is not saved correctly");
            Assert.AreEqual(15, vidokezo1.C_4o, "Report 1: Indicator 15 is not saved correctly");
            Assert.AreEqual(16, vidokezo1.C_4p, "Report 1: Indicator 16 is not saved correctly");
            Assert.AreEqual(17, vidokezo1.C_4q, "Report 1: Indicator 17 is not saved correctly");
            Assert.AreEqual(18, vidokezo1.C_4r, "Report 1: Indicator 18 is not saved correctly");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Saving_And_Updating_Vidokezo_Vya_Hatari_Report_Segment()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,Jan,2014,J20,K4,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,C20,K4,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            message = "ANC.04010100,Jan,2014,J20,K4,13,24,35,46,57,68,79,80,91,102,113,12,13,14,15,16,17,18,C20,K4,124,135,146,157,168,179,180,191,202,213,224,12,13,14,15,16,17,18";
            target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsNotNull(firstSavedForm.VidokezoVyaHatari_4id, "Report 1: Data Link was not established");
            Assert.AreEqual(firstSavedForm.VidokezoVyaHatari_4id, firstSavedForm.ANCForm_VidokezoVyaHatari.Id,
                "Report 1: Established link does not match with report details");

            Assert.IsNotNull(secondSavedForm.VidokezoVyaHatari_4id, "Report 2: Data Link was not established");
            Assert.AreEqual(secondSavedForm.VidokezoVyaHatari_4id, secondSavedForm.ANCForm_VidokezoVyaHatari.Id,
                "Report 2: Established link does not match with report details");

            var vidokezo1 = firstSavedForm.ANCForm_VidokezoVyaHatari;
            var vidokezo2 = secondSavedForm.ANCForm_VidokezoVyaHatari;

            Assert.IsNotNull(firstSavedForm.VidokezoVyaHatari_4id, "Report 1: Data Link was not established");
            Assert.AreEqual(firstSavedForm.VidokezoVyaHatari_4id, firstSavedForm.ANCForm_VidokezoVyaHatari.Id,
                "Report 1: Established link does not match with report details");

            Assert.IsNotNull(secondSavedForm.VidokezoVyaHatari_4id, "Report 2: Data Link was not established");
            Assert.AreEqual(secondSavedForm.VidokezoVyaHatari_4id, secondSavedForm.ANCForm_VidokezoVyaHatari.Id,
                "Report 2: Established link does not match with report details");

            Assert.AreEqual(13, vidokezo1.C_4a, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(24, vidokezo1.C_4b, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(35, vidokezo1.C_4c, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(46, vidokezo1.C_4d, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(57, vidokezo1.C_4e, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(68, vidokezo1.C_4f, "Report 1: Indicator 6 is not saved correctly");
            Assert.AreEqual(79, vidokezo1.C_4g, "Report 1: Indicator 7 is not saved correctly");
            Assert.AreEqual(80, vidokezo1.C_4h, "Report 1: Indicator 8 is not saved correctly");
            Assert.AreEqual(91, vidokezo1.C_4i, "Report 1: Indicator 9 is not saved correctly");
            Assert.AreEqual(102, vidokezo1.C_4j, "Report 1: Indicator 10 is not saved correctly");
            Assert.AreEqual(113, vidokezo1.C_4k, "Report 1: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, vidokezo1.C_4l, "Report 1: Indicator 12 is not saved correctly");
            Assert.AreEqual(13, vidokezo1.C_4m, "Report 1: Indicator 13 is not saved correctly");
            Assert.AreEqual(14, vidokezo1.C_4n, "Report 1: Indicator 14 is not saved correctly");
            Assert.AreEqual(15, vidokezo1.C_4o, "Report 1: Indicator 15 is not saved correctly");
            Assert.AreEqual(16, vidokezo1.C_4p, "Report 1: Indicator 16 is not saved correctly");
            Assert.AreEqual(17, vidokezo1.C_4q, "Report 1: Indicator 17 is not saved correctly");
            Assert.AreEqual(18, vidokezo1.C_4r, "Report 1: Indicator 18 is not saved correctly");

            Assert.AreEqual(124, vidokezo2.C_4a, "Report 2: Indicator 1 is not saved correctly");
            Assert.AreEqual(135, vidokezo2.C_4b, "Report 2: Indicator 2 is not saved correctly");
            Assert.AreEqual(146, vidokezo2.C_4c, "Report 2: Indicator 3 is not saved correctly");
            Assert.AreEqual(157, vidokezo2.C_4d, "Report 2: Indicator 4 is not saved correctly");
            Assert.AreEqual(168, vidokezo2.C_4e, "Report 2: Indicator 5 is not saved correctly");
            Assert.AreEqual(179, vidokezo2.C_4f, "Report 2: Indicator 6 is not saved correctly");
            Assert.AreEqual(180, vidokezo2.C_4g, "Report 2: Indicator 7 is not saved correctly");
            Assert.AreEqual(191, vidokezo2.C_4h, "Report 2: Indicator 8 is not saved correctly");
            Assert.AreEqual(202, vidokezo2.C_4i, "Report 2: Indicator 9 is not saved correctly");
            Assert.AreEqual(213, vidokezo2.C_4j, "Report 2: Indicator 10 is not saved correctly");
            Assert.AreEqual(224, vidokezo2.C_4k, "Report 2: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, vidokezo1.C_4l, "Report 1: Indicator 12 is not saved correctly");
            Assert.AreEqual(13, vidokezo1.C_4m, "Report 1: Indicator 13 is not saved correctly");
            Assert.AreEqual(14, vidokezo1.C_4n, "Report 1: Indicator 14 is not saved correctly");
            Assert.AreEqual(15, vidokezo1.C_4o, "Report 1: Indicator 15 is not saved correctly");
            Assert.AreEqual(16, vidokezo1.C_4p, "Report 1: Indicator 16 is not saved correctly");
            Assert.AreEqual(17, vidokezo1.C_4q, "Report 1: Indicator 17 is not saved correctly");
            Assert.AreEqual(18, vidokezo1.C_4r, "Report 1: Indicator 18 is not saved correctly");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Saving_Malaria_Report_Segment()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,Jan,2014,J20,K6,1,2,3,4,5,C20,K6,6,7,8,9,10";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            bool bActual = target.Save();

            Assert.IsTrue(bActual, target.ReportingError.ErrorText);
            var savedForms = target.SavedForms;
            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsNotNull(firstSavedForm.Malaria_6id, "Report 1: Data Link was not established");
            Assert.AreEqual(firstSavedForm.Malaria_6id, firstSavedForm.ANCForm_Malaria.Id,
                "Report 1: Established link does not match with report details");

            Assert.IsNotNull(secondSavedForm.Malaria_6id, "Report 2: Data Link was not established");
            Assert.AreEqual(secondSavedForm.Malaria_6id, secondSavedForm.ANCForm_Malaria.Id,
                "Report 2: Established link does not match with report details");

            var vidokezo1 = firstSavedForm.ANCForm_Malaria;
            var vidokezo2 = secondSavedForm.ANCForm_Malaria;

            Assert.AreEqual(1, vidokezo1.C_6a, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(2, vidokezo1.C_6b, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(3, vidokezo1.C_6c, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(4, vidokezo1.C_6d, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(5, vidokezo1.C_6e, "Report 1: Indicator 5 is not saved correctly");

            Assert.AreEqual(6, vidokezo2.C_6a, "Report 2: Indicator 1 is not saved correctly");
            Assert.AreEqual(7, vidokezo2.C_6b, "Report 2: Indicator 2 is not saved correctly");
            Assert.AreEqual(8, vidokezo2.C_6c, "Report 2: Indicator 3 is not saved correctly");
            Assert.AreEqual(9, vidokezo2.C_6d, "Report 2: Indicator 4 is not saved correctly");
            Assert.AreEqual(10, vidokezo2.C_6e, "Report 2: Indicator 5 is not saved correctly");
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Saving_And_Updating_Malaria_Report_Segment()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,Jan,2014,J20,K6,1,2,3,4,5,C20,K6,6,7,8,9,10";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            message = "ANC.04010100,Jan,2014,J20,K6,11,22,33,44,55,C20,K6,66,77,88,99,110";
            target = new ANCFormValidator(message, phoneNumber, format, mode);
            target.Save();

            var savedForms = target.SavedForms;
            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsNotNull(firstSavedForm.Malaria_6id, "Report 1: Data Link was not established");
            Assert.AreEqual(firstSavedForm.Malaria_6id, firstSavedForm.ANCForm_Malaria.Id,
                "Report 1: Established link does not match with report details");

            Assert.IsNotNull(secondSavedForm.Malaria_6id, "Report 2: Data Link was not established");
            Assert.AreEqual(secondSavedForm.Malaria_6id, secondSavedForm.ANCForm_Malaria.Id,
                "Report 2: Established link does not match with report details");

            var vidokezo1 = firstSavedForm.ANCForm_Malaria;
            var vidokezo2 = secondSavedForm.ANCForm_Malaria;

            Assert.AreEqual(11, vidokezo1.C_6a, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(22, vidokezo1.C_6b, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(33, vidokezo1.C_6c, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(44, vidokezo1.C_6d, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(55, vidokezo1.C_6e, "Report 1: Indicator 5 is not saved correctly");

            Assert.AreEqual(66, vidokezo2.C_6a, "Report 2: Indicator 1 is not saved correctly");
            Assert.AreEqual(77, vidokezo2.C_6b, "Report 2: Indicator 2 is not saved correctly");
            Assert.AreEqual(88, vidokezo2.C_6c, "Report 2: Indicator 3 is not saved correctly");
            Assert.AreEqual(99, vidokezo2.C_6d, "Report 2: Indicator 4 is not saved correctly");
            Assert.AreEqual(110, vidokezo2.C_6e, "Report 2: Indicator 5 is not saved correctly");
        }

        [TestMethod]
        public void MTUHA_Report_Consists_Of_All_Report_Segments()
        {
            Assert.Inconclusive("This needs time to prepare the test");
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,1,2014,C20,K1,1,C20,K3,7,C20,K7,9,C20,K8,5,C20,K9,6,C20,K10,7,J20,K1,7,J20,K3,1,J20,K7,3,J20,K8,0,J20,K9,9,J20,K10,8,C20,K2,2,3,5,4,5,9,6,J20,K2,6,5,11,4,3,7,2,C20,K4,8,9,1,2,3,4,5,6,7,8,9,J20,K4,0,9,8,7,6,5,4,3,2,1,0,C20,K5,1,2,3,4,5,6,7,8,9,0,1,2,3,J20,K5,9,8,7,6,5,34,2,1,0,9,8,7,6,C20,K6,4,5,6,7,8,J20,K6,5,4,3,2,1";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            
            Assert.IsTrue(target.Save(), target.ReportingError.ErrorText);            
        }

        [TestMethod]
        public void MTUHA_Report_Supports_ANC1_Keyword()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC1.04010100,12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Reporting_Using_Desktop_Credentials()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,12,2013,J20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string username = "admin";
            string password = DataTransformation.Encrypt("admin");
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            DataInputingMethod inputMethod = DataInputingMethod.DESKTOP_DATA_CAPTURE;
            ANCFormValidator target = new ANCFormValidator(message, username, format, mode, inputMethod, password);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException), "SMS Reporting does not require password logging")]
        public void Password_Rejected_SMS_Reporting()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,12,2013,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13";
            string username = "admin";
            string password = DataTransformation.Encrypt("admin");
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            DataInputingMethod inputMethod = DataInputingMethod.SMS;
            ANCFormValidator target = new ANCFormValidator(message, username, format, mode, inputMethod, password);
        }

        [TestMethod]
        public void Reporting_And_Updating_Using_Desktop_Credentials()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,12,2013,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string username = "admin";
            string password = DataTransformation.Encrypt("admin");
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            DataInputingMethod inputMethod = DataInputingMethod.DESKTOP_DATA_CAPTURE;
            ANCFormValidator target = new ANCFormValidator(message, username, format, mode, inputMethod, password);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            message = "ANC.04010100,12,2013,C20,K5,10,100,70,20,50,10,100,70,30,00,70,10,10,10,10,10,20";
            target = new ANCFormValidator(message, username, format, mode, inputMethod, password);
            bActual = target.Save();
            Assert.IsTrue(bActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Reporting_Using_MTUHA_And_AutoSaved_To_Classical_Templates()
        {
            Assert.Inconclusive("The feature is becoming obselete");
            string facilityCode = "04010100";
            int month = 1;
            int year = 2014;
            string reportKeyword = "K5J20";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.RemoveReportIfExists(facilityCode, reportKeyword, month, year);

            string message = string.Format("ANC.{0},{1},{2},J20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13",
                facilityCode, month, year);
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == reportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved in classical report templates");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(16, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(1, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(2, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(3, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(4, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(5, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(6, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(7, int.Parse(data[9].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(8, int.Parse(data[10].Data), "Indicator 8 is not saved well");
                Assert.AreEqual(9, int.Parse(data[11].Data), "Indicator 9 is not saved well");
                Assert.AreEqual(10, int.Parse(data[12].Data), "Indicator 10 is not saved well");
                Assert.AreEqual(11, int.Parse(data[13].Data), "Indicator 11 is not saved well");
                Assert.AreEqual(12, int.Parse(data[14].Data), "Indicator 12 is not saved well");
                Assert.AreEqual(13, int.Parse(data[15].Data), "Indicator 13 is not saved well"); 
            }
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void Reporting_Using_MTUHA_And_AutoSaved_To_Classical_Templates_Matches()
        {
            Assert.Inconclusive("The feature is becoming obselete");
            string facilityCode = "04010100";
            int month = 1;
            int year = 2014;
            string reportKeyword = "K5J20";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.RemoveReportIfExists(facilityCode, reportKeyword, month, year);

            string message = string.Format("ANC.{0},{1},{2},J20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13",
                facilityCode, month, year);
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            Assert.AreEqual(1, target.SavedForms.Count, "More than one report was saved");
            var savedForm = target.SavedForms[0];
            var report = savedForm.ANCForm_PMTCT;
            Assert.IsFalse(report.LessThan20, "Report category is not saved properly");

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == reportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved in classical report templates");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(16, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(report.FacilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(report.Month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(report.Year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(report.C_5a, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(report.C_5b, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(report.C_5c, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(report.C_5d, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(report.C_5e, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(report.C_5f, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(report.C_5g, int.Parse(data[9].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(report.C_5h, int.Parse(data[10].Data), "Indicator 8 is not saved well");
                Assert.AreEqual(report.C_5i, int.Parse(data[11].Data), "Indicator 9 is not saved well");
                Assert.AreEqual(report.C_5j, int.Parse(data[12].Data), "Indicator 10 is not saved well");
                Assert.AreEqual(report.C_5k, int.Parse(data[13].Data), "Indicator 11 is not saved well");
                Assert.AreEqual(report.C_5l, int.Parse(data[14].Data), "Indicator 12 is not saved well");
                Assert.AreEqual(report.C_5m, int.Parse(data[15].Data), "Indicator 13 is not saved well");
            }
        }

        [TestMethod]
        public void Case_InsensitiveReporting()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "anc.04010100,5,2013,c20,k5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            
            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void Position_Of_Age_Category_And_Report_Section_Can_Be_Interchanged()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "anc.04010100,5,2013,K5,c20,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            DataInputingMethod inputMethod = DataInputingMethod.SMS;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode, inputMethod, null, true);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_ANC_Form_Section_2_Implements_BusinessRules()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, "04010100");

            string message = string.Format("ANC.{0},3,2014,C20,K2,1,1,1,1,1,1,1", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.BUSINESS_RULES_FAILURE;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_ANC_Form_Section_2_Implements_BusinessRules_Saved()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;
            string classicalReportKeyword = "HKC20";
            string message = string.Format("ANC.{0},{1},{2},C20,K2,1,1,2,1,1,3,1", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == classicalReportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved at all");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(10, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(1, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(1, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(2, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(1, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(1, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(3, int.Parse(data[8].Data), "Indicator 6 is not saved well");     
                Assert.AreEqual(1, int.Parse(data[9].Data), "Indicator 7 is not saved well"); 
            }
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_ANC_Form_Section_5_Implements_BusinessRules()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            string message = string.Format("ANC.{0},3,2014,C20,K5,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.BUSINESS_RULES_FAILURE;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_ANC_Form_Section_5_Implements_BusinessRules_Saved()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;
            string classicalReportKeyword = "DPMC20";
            string message = string.Format("ANC.{0},{1},{2},C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1,1,2", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == classicalReportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved at all");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(20, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(1, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(10, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(7, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(2, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(5, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(1, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(10, int.Parse(data[9].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(7, int.Parse(data[10].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(3, int.Parse(data[11].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(0, int.Parse(data[12].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(7, int.Parse(data[13].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(1, int.Parse(data[14].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(1, int.Parse(data[15].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(1, int.Parse(data[16].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(1, int.Parse(data[17].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(1, int.Parse(data[18].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(2, int.Parse(data[19].Data), "Indicator 3 is not saved well");
            }
        }

        [TestMethod]
        [Owner("Ibrahim Mgawe")]
        public void MTUHA_ANC_Form_Has_Age_Category_And_Section_Number_Separate_By_Period()
        {
            Assert.Fail("This feature is not implemented yet, but it's useful");
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_MAT_Form_Section_2_Implements_BusinessRules()
        {
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            string message = string.Format("MAT.{0},3,2014,C20,K2,1,1,1,1,1,1,1", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.BUSINESS_RULES_FAILURE;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_MAT_Form_Section_2_Implements_BusinessRules_Saved()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;
            string classicalReportKeyword = "TWC20";
            string message = string.Format("MAT.{0},{1},{2},C20,K2,1,1,2,1,5,3,0", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == classicalReportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved at all");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(10, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(1, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(1, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(2, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(1, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(5, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(3, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(0, int.Parse(data[9].Data), "Indicator 7 is not saved well");
            }
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_MAT_Form_Section_8_Implements_BusinessRules()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            string message = string.Format("MAT.{0},3,2014,C20,K8,1,2,3,4,5,6,7,8,9,10,11,12,13,14", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = false;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.BUSINESS_RULES_FAILURE;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_MAT_Form_Section_8_Implements_BusinessRules_Saved()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;
            string classicalReportKeyword = "PMTC20";
            string message = string.Format("MAT.{0},{1},{2},C20,K8,65,5,0,3,7,1,0,1,6,6,0,0,0,1", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == classicalReportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved at all");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(17, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(65, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(5, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(0, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(3, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(7, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(1, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(0, int.Parse(data[9].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(1, int.Parse(data[10].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(6, int.Parse(data[11].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(6, int.Parse(data[12].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(0, int.Parse(data[13].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(0, int.Parse(data[14].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(0, int.Parse(data[15].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(1, int.Parse(data[16].Data), "Indicator 7 is not saved well");
            }
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_Reports_Ends_With_Updating_Keyword()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;
            string classicalReportKeyword = "PMTC20";
            string message = string.Format("MAT.{0},{1},{2},C20,K8,65,5,0,3,7,1,0,1,6,6,0,0,0,1,badili", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == classicalReportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved at all");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(17, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(65, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(5, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(0, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(3, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(7, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(1, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(0, int.Parse(data[9].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(1, int.Parse(data[10].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(6, int.Parse(data[11].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(6, int.Parse(data[12].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(0, int.Parse(data[13].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(0, int.Parse(data[14].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(0, int.Parse(data[15].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(1, int.Parse(data[16].Data), "Indicator 7 is not saved well");
            }
        }

        [TestMethod()]
        [Owner("Moses Kehengu")]
        public void MTUHA_Reports_Disallow_Report_Updating_Without_Its_Updating_Keyword()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;

            string message = string.Format("MAT.{0},{1},{2},C20,K8,60,5,0,3,7,1,0,1,6,6,0,0,0,1", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            message = string.Format("MAT.{0},{1},{2},C20,K8,65,5,0,3,7,1,0,1,6,6,0,0,0,1", facilityCode, month, year);
            target = new LDFormValidator(message, phoneNumber, format, mode);

            bExpected = false;
            bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            eExpected = ReportProcessingError.REPORT_ALREADY_SUBMITTED;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);
        }

        [TestMethod]
        public void All_Inline_Report_Data_Indicators_Are_Saved_And_Uploaded_To_DHIS()
        {
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, "04010100");

            string message = string.Format("ANC.{0},1,2014,C20,K1,1,c20,k3,2,c20,k7,3,c20,k8,4,c20,k9,5,c20,k10,6,j20,k1,7,j20,k3,8,j20,k7,9,j20,k8,10,j20,k9,11,J20,K10,12", facilityCode);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);
            AuthorizationAgent agent = new AuthorizationAgent("admin", "district");
            bool savedAndUploaded = target.SaveAndUploadToDHIS(agent.AuthorizationText);

            var savedForms = target.SavedForms;
            Assert.AreEqual(2, savedForms.Count, "Not all two reports were saved - " + target.ReportingError.ErrorText);

            ANCForm firstSavedForm = savedForms[0];
            ANCForm secondSavedForm = savedForms[1];

            Assert.IsTrue(firstSavedForm.LessThan20, "Report 1: Report age category was not saved correctly");
            Assert.IsFalse(secondSavedForm.LessThan20, "Report 2: Report age category was not saved correctly");

            Assert.AreEqual(1, firstSavedForm.C_1, "Report 1: Indicator 1 is not saved correctly");
            Assert.AreEqual(2, firstSavedForm.C_3, "Report 1: Indicator 2 is not saved correctly");
            Assert.AreEqual(3, firstSavedForm.C_7, "Report 1: Indicator 3 is not saved correctly");
            Assert.AreEqual(4, firstSavedForm.C_8, "Report 1: Indicator 4 is not saved correctly");
            Assert.AreEqual(5, firstSavedForm.C_9, "Report 1: Indicator 5 is not saved correctly");
            Assert.AreEqual(6, firstSavedForm.C_10, "Report 1: Indicator 6 is not saved correctly");

            Assert.AreEqual(7, secondSavedForm.C_1, "Report 2: Indicator 7 is not saved correctly");
            Assert.AreEqual(8, secondSavedForm.C_3, "Report 2: Indicator 8 is not saved correctly");
            Assert.AreEqual(9, secondSavedForm.C_7, "Report 2: Indicator 9 is not saved correctly");
            Assert.AreEqual(10, secondSavedForm.C_8, "Report 2: Indicator 10 is not saved correctly");
            Assert.AreEqual(11, secondSavedForm.C_9, "Report 2: Indicator 11 is not saved correctly");
            Assert.AreEqual(12, secondSavedForm.C_10, "Report 2: Indicator 12 is not saved correctly");

            Assert.Inconclusive("More testing scenario required");
        }

        [TestMethod]
        public void MTUHA_Report_Supports_PMTCT_Section_With_Fewer_Indicator_New_Tools()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "ANC.04010100,12,2014,C20,K5,1,10,7,2,5,1,10,7,3,0,7,1,1,1,1";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            ANCFormValidator target = new ANCFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }
                

        [TestMethod]
        public void MTUHA_Report_Supports_Waliojifungua_Section_With_Fewer_Indicator_New_Tools()
        {
            TestDataInitializer.TruncateRelatedOptionBPlusTables();

            string message = "MAT.04010100,12,2014,C20,K2,1,10,7,2,20,1";
            string phoneNumber = "+255763986451";
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);
        }

        [TestMethod]
        [Owner("Moses Kehengu")]
        public void MTUHA_MAT_Form_Section_8_Implements_BusinessRules_Saved_New_Tools()
        {
            //AppConfiguration.DBConnectionString = @"Data Source=41.73.195.220\SQL2008R2;Initial Catalog=IQSMS_TestDB;User ID=sa;Password=c0nstella";          
            string phoneNumber = "+255763986451";
            string facilityCode = "04010100";
            TestDataInitializer.TruncateRelatedOptionBPlusTables();
            TestDataInitializer.TryToRegisterUser(phoneNumber, facilityCode);

            int month = 3;
            int year = 2014;
            string classicalReportKeyword = "ADMC20";
            string message = string.Format("MAT.{0},{1},{2},C20,K8,65,5,0,3,7,1,0,1,6", facilityCode, month, year);
            SMSReportingFormat format = SMSReportingFormat.RESTRICTIVE;
            ReportingMode mode = ReportingMode.DEFAULT;
            LDFormValidator target = new LDFormValidator(message, phoneNumber, format, mode);

            bool bExpected = true;
            bool bActual = target.Save();
            Assert.AreEqual(bExpected, bActual, target.ReportingError.ErrorText);

            var eExpected = ReportProcessingError.NO_ERROR;
            Assert.AreEqual(eExpected, target.ReportingError.Type, target.ReportingError.ErrorText);

            using (var db = new IQSMS_TestDBContext())
            {
                var receivedSMS = (from r in db.ReceivedSMS.Include("ReportDatas")
                                   where r.FacCode == facilityCode &&
                                   r.Period == month && r.Year == year &&
                                   r.Report.RepVersion == classicalReportKeyword
                                   select r).FirstOrDefault();

                Assert.IsNotNull(receivedSMS, "Report was not saved at all");
                Assert.IsNotNull(receivedSMS.ReportDatas, "Report data was not saved in classical report templates");

                var data = receivedSMS.ReportDatas;
                Assert.AreEqual(12, data.Count, "Saved report indicators does not match that of the report");

                Assert.AreEqual(facilityCode, data[0].Data, "Facility code is not saved well");
                Assert.AreEqual(month, int.Parse(data[1].Data), "Report month is not saved well");
                Assert.AreEqual(year, int.Parse(data[2].Data), "Report year is not saved well");
                Assert.AreEqual(65, int.Parse(data[3].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(5, int.Parse(data[4].Data), "Indicator 2 is not saved well");
                Assert.AreEqual(0, int.Parse(data[5].Data), "Indicator 3 is not saved well");
                Assert.AreEqual(3, int.Parse(data[6].Data), "Indicator 4 is not saved well");
                Assert.AreEqual(7, int.Parse(data[7].Data), "Indicator 5 is not saved well");
                Assert.AreEqual(1, int.Parse(data[8].Data), "Indicator 6 is not saved well");
                Assert.AreEqual(0, int.Parse(data[9].Data), "Indicator 7 is not saved well");
                Assert.AreEqual(1, int.Parse(data[10].Data), "Indicator 1 is not saved well");
                Assert.AreEqual(6, int.Parse(data[11].Data), "Indicator 2 is not saved well");
            }
        }
        #endregion
    }
}
